package com.ruoyi.edge.application.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.application.domain.SourceProject;
import com.ruoyi.edge.application.mapper.SourceProjectMapper;
import com.ruoyi.edge.application.service.SourceProjectService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 源代码项目管理
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class SourceProjectServiceImpl implements SourceProjectService {

    private final SourceProjectMapper sourceProjectMapper;

    @Override
    public TableDataInfo<SourceProject> listPage(SourceProject sourceProject, PageQuery pageQuery) {

        LambdaQueryWrapper<SourceProject> lqw = new LambdaQueryWrapper<>();
        Page<SourceProject> page = sourceProjectMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public R<SourceProject> get(String id) {
        SourceProject sourceProject = sourceProjectMapper.selectById(id);
        return R.ok(sourceProject);
    }

    @Override
    public R<String> add(SourceProject sourceProject) {
        sourceProjectMapper.insert(sourceProject);
        return R.ok("新增成功");
    }

    @Override
    public R<String> edit(SourceProject sourceProject) {
        sourceProjectMapper.updateById(sourceProject);
        return R.ok("修改成功");
    }

    @Override
    public R<String> remove(String id) {
        sourceProjectMapper.deleteById(id);
        return R.ok("删除成功");
    }
}
